<template>
  <div>
<!--    <el-button type="text" @click="dialogFormVisible = true">打开嵌套表单的 Dialog</el-button>-->
    <el-button
        type="primary"
        class="handle-del mr10"
        @click="dialogFormVisible = true"
        icon="el-icon-circle-plus-outline"
    >添加学校举办者</el-button>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="ruleForm" :rules="rules" :inline="true" ref="ruleForm" label-width="180px" class="demo-ruleForm">
        <el-form-item label="学校举办者代码" prop="schoolhostcode">
          <el-input v-model="ruleForm.schoolhostcode"></el-input>
        </el-form-item>
        <el-form-item label="学校举办者名称" prop="schoolhostname">
          <el-input v-model="ruleForm.schoolhostname"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('ruleForm')">立即添加</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
<!--        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>-->
      </div>
    </el-dialog>

  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        // id:'',
        schoolhostcode: '',
        schoolhostname: ''
      },
      rules: {
        schoolhostcode: [
          {required: true, message: '请填写学校举办者代码', trigger: 'blur'}
        ],
        schoolhostname: [
          {required: true, message: '请填写学校举办者名称', trigger: 'blur'}
        ],
      },
      dialogTableVisible: false,
      dialogFormVisible: false,
      formLabelWidth: '120px'
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("http://localhost:8081/schoolhost/save", this.ruleForm).then(function (res) {
            if (res.data.msg === "添加成功") {
              _this.$message({
                message: '添加成功！',
                type: 'success'
                //添加成功后页面跳转
              });
              _this.$router.push('/SchoolHost')
            } else {
              _this.$message({
                message: '学校举办者代码重复！请重新输入',
                type: 'fail'
              });
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}

</script>